﻿using System;
using System.Collections.Generic;
using System.Text;
using MemoryGameBL;

namespace C11_Ex02
{
    public class BoardConsoleDrawer
    {
        /// <summary>
        /// Draws a given board on the console.
        /// </summary>
        /// <param name="i_Board">The board to draw on the console.</param>
        public void DrawBoard(Board i_Board)
        {
            Console.Write("  ");

            for (char i = 'A'; i - 'A' < i_Board.NumberOfColumns; i++)
            {
                string topIndex = string.Format("  {0} ", i);
                Console.Write(topIndex);
            }

            Console.WriteLine();
            this.drawHorizontalSeparator(i_Board.NumberOfColumns);
            Console.WriteLine();

            for (int i = 1; i < i_Board.NumberOfRows + 1; i++)
            {
                this.drawHorizontalLine(i_Board, i);
                Console.WriteLine();
                this.drawHorizontalSeparator(i_Board.NumberOfColumns);
                Console.WriteLine();
            }
        }

        private void drawHorizontalSeparator(int i_Width)
        {
            Console.Write("  ");

            for (int i = 0; i < (i_Width * 4) + 1; i++)
            {
                Console.Write("=");
            }
        }

        private void drawHorizontalLine(Board i_Board, int i_RowIndex)
        {
            string beginningOfLine = string.Format("{0} |", i_RowIndex);
            Console.Write(beginningOfLine);

            for (char i = 'A'; i - 'A' < i_Board.NumberOfColumns; i++)
            {
                Console.Write(" {0} |", i_Board[i_RowIndex, i]);
            }
        }
    }
}
